import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import component.LeftFun
import component.RightTopInfo
import content.repository.MenuRepository
import theme.DarkColorPalette
import theme.SlackColors
import theme.divider
import theme.typography

@Composable
@Preview
fun App() {

    MaterialTheme(colors = DarkColorPalette, typography = typography) {
        Row(modifier = Modifier.background(
                color = MaterialTheme.colors.surface
            ).fillMaxSize()
        ) {

            // 默认选中的菜单，选中第一个
            val selectedMenu = remember { mutableStateOf(MenuRepository.menuList.first()) }

            LeftFun(
                menuList = MenuRepository.menuList,
                selectedMenu = selectedMenu.value,
                onMenuClick = {
                    selectedMenu.value = it
                }
            )

            // 右侧内容
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(
                       color = SlackColors.detailsBg
                    )
            ) {
                RightTopInfo(selectedMenu.value)

                Divider(color = divider)

                selectedMenu.value.content()
            }
        }

    }
}

fun main() = application {
    Window(onCloseRequest = ::exitApplication,
        state = WindowState(width = 1000.dp, height = 720.dp),
        resizable = false,
        title = "番茄工具集",
        icon = painterResource("tomato.png")) {
        App()
    }
}
